package com.yi.wood.dao;

import com.yi.wood.entity.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author moyi
 */
public interface RoleDao extends JpaRepository<Role,Long> {
    /**
     * 通过用户ID查询用户所有的角色
     * @param userId 用户ID
     * @return 用户角色列表
     */
    @Query(value = "select * from `role` as r left join `user_role` as ur on r.id = ur.role_id where ur.user_id =:userId", nativeQuery = true)
    List<Role> queryRoleByUserId(Long userId);
}
